
*Master do file
clear
clear matrix
clear mata
set maxvar 15000

ssc install maptile
ssc install spmap
cap ssc uninstall parmest
ssc install parmest
cap maptile_install using "http://files.michaelstepner.com/geo_county2000.zip"
cap maptile_install using "http://files.michaelstepner.com/geo_state.zip"
ssc install tabout
ssc install reghdfe
ssc install outreg2

capture log close
set matsize 11000
log using replication.log, append

*Appendix Table A39: Comparison of Opportunity Insights Characteristics
do OppInsights_Characteristics.do

*Figure 1: Fraction of Parents by National Income Decile, Opportunity Insights
do make_fraction_parent_income_graph.do

*Appendix Figure A3: Opportunity Insights analysis conditional on parental structure
do FamilyStructure.do

*Table A1: 1850 Characteristics
do 1850_balance_ipums_nhgis.do

*Table A38: Educational Mobility, using data from Card, Domnisoru, and Taylor (2022)
do EdMobility_1940_CardDomnisoruTaylor.do

*Variables for Table A35, A36, A37, and regressions for Table A35
do 1940_nhgis.do

*Table A36: Occupation and Industry in 1940
do 1940_fullcount_industry.do

*Table A37: Education in 1940
do 1940_fullcount_attendance.do

*Footnote 1 statistic: fraction of students from bottom two parental income quintiles
do parentquintile_bycollege.do

*Footnote 12 statistic: 1987 Carnegie classifications of colleges that started as normal schools
do normal_regionalpublic.do

* Figures that show the distribution of effects across income percentiles (Figure 2, 3, 4)**
do make_distributional_graphs

* Comparison of Effect on Place and on Persons Table 3, A40, A41, A42 **
do causal_tables

* Comparison of Effect on Place and on Persons at the 75th percentile (Table A43) **
do causal_tables_p75

*multiple hypothesis testing analysis (Figures A4, statistics in text in Appendix D.2) **
do romano_wolf

* Principle Component Analysis (Figure A5) **
do principal_component_analysis

*Main results by age and sex
*Results by Race (Figure A10) **
do make_distributional_graphs_race
*Results by Sex (Figure A11) **
do make_distributional_graphs_sex


//Selection by Age moving into Normal and Asylum PUMAs (Table A44, Figure A12) **

do create_puma_to_county_crosswalk
do import_acs_data
do moving_selection_acs_mom_pop


*TFS: None of the TFS do files will run with only the data in the replication package
//as they use restricted data.

//The below do file creates the TFS dataset and was run on a server with two 
//Intel Xeon E5-2640v2 8-cores (16-thread) 2.00 GHz processors and 396 GB of RAM memory.

do TFS_construction.do 

// Runs TFS code

*Creates "tfs_cleaned.dta"
do "tfsanalysis_clean"
*Main TFS Analysis (Figure 5, A15) **
do "tfsanalysis"
*Other TFS outcomes (Figure A14) **
do "tfsanalysis_appendix"

*TFS Distance Outcomes (Table 4, Figure A13, Table A46, Table A47) **
do "tfsanalysis_university_distance_yearfe_comparison"

* TFS Summary statistics in footnote 69 **
do "tfsanalysis_summarystats"

*TFS Splits by Parental Income (Figure A16) **
do "tfsanalysis_low_and_high_income"

// Close vs Far Asylums

*Create Fiugre A6, and the "closeasylums.dta" dataset **
do "closeasylum"

*Figures A7, A8, A9 **
do "make_distributional_graphs_closeasylums"



// Similar Figures to REStat paper
//Table A2 **
do "county_highered"
// FIgure A1a **
do "figure1a_do"
//Figure A1b **
do "figure1b_do"
//Figure A1c **
do "figure1c_do"


*Tables 1 (columns 3-6), A5, A6, A7, A8, A9: Census Tree 1850-1860 analysis
do censustreemerge18501860.do

*Appendix Figure A2, Table 1 columns 1 and 2, Table A19 columns 1 and 2: Education Mobility 1850
do enroll1850_livingwithparents.do

*Tables 2, A10, A11, A12, A13, A15, A16, A17: Census Tree 1920-1940 analysis
do censustreemerge2040.do

*Tables A33 and A34: Predicted son's occupational score rank conditional on father's rank, 1920-1940
do censustreemerge2040_meanrank.do

*Table A32: Predicted son's occupational score rank conditional on father's rank, 1850-1860
do censustreemerge1850_meanrank.do

*Tables A24, A25, A26, A27, A28, A29, A30, A31: Representativeness of Census Tree Links 1920-1940
do CensusTree2040_differentialmerging.do

*Tables A18, A19 (col. 3-6), A20, A21, A22, A23: Representativeness of Census Tree Links 1850-1860
do diffmerge1850.do

*Table A3: University Characteristics
do InstChars_cost.do
do InstChars_selectivity.do
do InstChars_grad.do

*Appendix A1 text statistic, third paragraph: number of counties with four-year universities
do InstChars_sumfouryr.do

*Footnote 12 Text Statistic: 2000 Carnegie Rating
do carnegierating.do

*Table A14: Work Relief
do censustreemerge2040_workrelief.do

*Appendix D6, fourth paragraph statistic: effects on exactly some college for Black individuals
do exactsomecoll.do

*Footnote 47 (in online appendix) statistic: Literacy rate 1850
do literacy_above25_1850.do

*Table A4: State income per capita and number of institutions
do stateincomepercapita.do

